package com.carolouvindam.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class OurSQLiteOpenHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "cakeathomedb";
    private static final int DATABASE_VERSION = 1;


    private static final String[] CREATE_BASE = new String []{
            OrderTable.CREATE,
            OrderHasProductTable.CREATE };


    public OurSQLiteOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        for(String s : CREATE_BASE) {

            database.execSQL(s);

        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABlE "+ OrderTable.TABLESNAME );
        db.execSQL("DROP TABlE "+ OrderHasProductTable.TABLESNAME );
        for(String s : CREATE_BASE) {

            db.execSQL(s);

        }
    }

}
